package com.my.app.tools.util;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5 加密工具类
 *
 * @author Huang feifei
 * @date 2017/3/29 14:27
 */
public class MD5Util {

    /**
     * MD5加密，32位小写
     *
     * @param str 需要加密的字符串
     * @return 加密后的字符串
     * @author Huang feifie
     * @date 2017/3/29 14:29
     */
    public static String encrypt(String str) {
        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] bs = digest.digest(str.getBytes());
            String hexString = "";
            for (byte b : bs) {
                int temp = b & 255;
                if (temp < 16 && temp >= 0) {
                    hexString = hexString + "0" + Integer.toHexString(temp);
                } else {
                    hexString = hexString + Integer.toHexString(temp);
                }
            }
            return hexString;
        } catch (NoSuchAlgorithmException e) {
        }
        return "";
    }

}